
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_demo/res/colors.dart';
import 'package:flutter_demo/res/dimens.dart';
import 'package:flutter_demo/res/gaps.dart';
import 'package:flutter_demo/util/image_utils.dart';
import 'package:flutter_demo/util/theme_utils.dart';
import 'package:flutter_demo/widgets/circle_button.dart';
import 'package:flutter_demo/widgets/load_image.dart';

class TopBarWidget extends StatelessWidget {
  final bool isShowFloatingTopBar;
  final double topBarOpactiy;
  final Widget contentWidget;
  final List<Widget> actions;
  final Color backgroundColor;
  double _topBarHeight = 48.0;
  BuildContext _context;

  TopBarWidget({
    Key key,
    this.isShowFloatingTopBar = false,
    this.topBarOpactiy = 1,
    this.contentWidget,
    this.actions,
    this.backgroundColor,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Color _backgroundColor;
    if (_backgroundColor == null){
      _backgroundColor = ThemeUtils.getBackgroundColor(context);
    }else{
      _backgroundColor = backgroundColor;
    }
    //黑色主题切换
    SystemUiOverlayStyle _overlayStyle = ThemeData.estimateBrightnessForColor(_backgroundColor) != Brightness.dark
    ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark;

    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: _overlayStyle,
      child: Container(
        // width: double.infinity,
        color:Colors.white,
        height:ScreenUtil.getScreenH(context)/4+60,
        child: Stack(
          children: <Widget>[
            AnimatedPositioned(
              curve: Curves.easeInOut,
              duration: const Duration(milliseconds: 500),
              left: 0,
              top: 0,
              child: Container(
                decoration: new BoxDecoration(
                  image: DecorationImage(
                    image: ImageUtils.getAssetImage('scene/scene_bg'),
                    fit: BoxFit.fill
                  ),
                  // gradient:  Colours.primaryGradient,
                ),
                width: ScreenUtil.getScreenW(context),
                height: ScreenUtil.getScreenH(context) / 4
              ),
            ),
            Opacity(
              opacity: 1,
              child: Container(
                margin: EdgeInsets.only(top: ScreenUtil.getStatusBarH(context)+25.0),
                child: Column(
                  children: <Widget>[
                    Opacity(
                      opacity: topBarOpactiy,
                      child: _buildTopBar(),
                    ),
                  ],
                ),
              ),
            ),
            Positioned(
              top: _topBarHeight+ScreenUtil.getStatusBarH(context)+20,
              child: Opacity(
                opacity: topBarOpactiy,
                child: Container(
                  width: ScreenUtil.getScreenW(context),
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.only(top:5.0,left:25.0),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: <Widget>[
                        Text('大丰区智慧技防项目',style:TextStyle(color:Colors.white,fontSize: Dimens.font_sp18)),
                        Gaps.hGap8,
                        DecoratedBox(
                          decoration:new BoxDecoration(
                            color:Color.fromRGBO(247, 180, 37, 1.0),
                            borderRadius: BorderRadius.all(Radius.circular(2.0)),
                          ),
                          child: Padding(
                            padding: EdgeInsets.symmetric(
                              horizontal:5.0,
                              vertical: 3.0,
                            ),
                            child: Text('施工中',style:TextStyle(color:Colors.white,fontSize: Dimens.gap_dp10)),
                          )
                        )
                      ],),
                      Text('共计1000个点位',style:TextStyle(color:Colours.text_gray_c,fontSize: Dimens.font_sp12))
                    ],
                  ),
                )
                
              ),
            ),
            Positioned(
              top: _topBarHeight+ScreenUtil.getStatusBarH(context)+75.0,
              child: Container(
                  width: ScreenUtil.getScreenW(context)-20.0,
                  height: ScreenUtil.getScaleH(context, 90.0),
                  margin: EdgeInsets.all(10.0),
                  alignment: Alignment.center,
                  padding: EdgeInsets.all(5.0),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(6.0)),
                    boxShadow: [
                      BoxShadow(
                        offset: Offset(0.0,5.0),
                        color: Color.fromRGBO(237, 245, 254, 0.8),
                        blurRadius: 2.0,
                        // spreadRadius:2.0,
                      )
                    ]
                  ),
                  child: Container(
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      mainAxisSize: MainAxisSize.max,
                      children: <Widget>[
                        CircleButton(
                          icon: const LoadAssetImage('scene/map', width: 60.0),
                          text: '地图',
                        ),
                        CircleButton(
                          icon: const LoadAssetImage('scene/draftbox', width: 60.0),
                          text: '草稿箱'
                        ),
                        CircleButton(
                          icon: const LoadAssetImage('scene/submit', width: 60.0),
                          text:'已提交'
                        )
                      ],
                    ),
                  ),
                ),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildTopBar() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        Container(
          width: 75.0,
          child: GestureDetector(
            onTap: (){debugPrint('ontap post');},
            child: Row(
              children: <Widget>[
                Gaps.hGap10,
                Icon(Icons.location_on,size: 16.0,color: Colors.white,),
                Gaps.hGap5,
                Text('南京市',style:TextStyle(fontSize: Dimens.font_sp14,color:Colors.white)),
              ],
            ),
          ),
        ),       
        Expanded(
          child: Container(
            alignment: Alignment.center,
            child: Text('现场',style:TextStyle(fontSize:Dimens.font_sp18,color:Colors.white,)),
          ),
        ),
        Container(
          width: 75.0,
          alignment: Alignment.centerRight,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              ...actions.map((wid){
                return Container(
                  child: wid,
                );
              }).toList(),
            ],
          ),
        ),
        
        Gaps.hGap5
        
      ],
    );
  }
}